package spittr.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * Created by gongyan on 17/4/5.
 */
@Configuration
@EnableWebMvc // 启动springMVC组件
@ComponentScan("spitter.web") // 扫描
public class WebConfig extends WebMvcConfigurerAdapter{

    /**
     * 配置JSP视图解析器
     * @return
     */
    @Bean
    public ViewResolver viewResolver(){
        InternalResourceViewResolver defResolver = new InternalResourceViewResolver();
        defResolver.setPrefix("/WEB-INF/views/");
        defResolver.setSuffix(".jsp");
        defResolver.setExposeContextBeansAsAttributes(true);
        return defResolver;
    }

    /**
     * 配置静态资源的处理类
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        super.configureDefaultServletHandling(configurer);
        configurer.enable(); // 将静态资源的请求转发到Servlet容器中的默认Servlet上面
    }
}
